package io.kiki.sba.registry.server.clientInterface.remoting.console.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.Response;
import io.kiki.sba.registry.common.model.sessionserver.ClientOnRequest;
import io.kiki.sba.registry.server.clientInterface.connections.ConnectionsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public final class ClientOnRequestHandler extends AbstractConsoleHandler<ClientOnRequest> {
    private static final Logger logger = LoggerFactory.getLogger(ClientOnRequestHandler.class);

    @Autowired
    protected ConnectionsService connectionsService;

    @Override
    public Object doHandle(Channel channel, ClientOnRequest request) {
        List<String> conIds = connectionsService.closeIpConnects(request.getIps());
        logger.info("clientOn conIds: {}", conIds);
        return Response.buildSuccessResponse();
    }

    @Override
    public Class interest() {
        return ClientOnRequest.class;
    }

    @Override
    public Object buildFailedResponse(String msg) {
        return Response.buildFailedResponse(msg);
    }
}
